IF NOT EXISTS (SELECT 1 FROM sys.objects
					 WHERE type ='u' AND object_id = OBJECT_ID('MD3.Log'))
BEGIN
	
	CREATE TABLE MD3.Log
	   (Id              BIGINT IDENTITY(1,1) NOT NULL
	   ,DTime           DATETIME2            NOT NULL
	   ,Severity             CHAR(1)         NOT NULL
	   ,ScriptName         NVARCHAR(256)        NULL
	   ,ProcName           NVARCHAR(256)        NULL
	   ,Message       NVARCHAR(MAX)        NOT NULL
	   ,ErrorMessage	NVARCHAR(MAX)		NULL
	   ,ErrorNumber		INT					NULL
	   ,ErrorLine		INT					NULL
	   ,ErrorSeverity	INT					NULL
	   ,ErrorState		INT					NULL
	);
	   
	ALTER TABLE MD3.Log ADD CONSTRAINT LogPK 
	PRIMARY KEY CLUSTERED (Id);

	ALTER TABLE MD3.Log WITH CHECK 
		ADD CONSTRAINT SeverityCheck
			CHECK (Severity IN ('D','I','W','E'));
		
END 


